
package com.chenpeijian.demo.demos.web.controller;

import com.chenpeijian.demo.service.entity.Order;
import com.chenpeijian.demo.service.mapper.OrderMapper;
import com.chenpeijian.demo.service.statemachine.OrderServiceImpl;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: student_code
 * @description: 状态机接口类
 * @author: 陈培建
 * @create: 2024-12-10 15:37
 **/

@RestController
@RequestMapping("/order")
@Tag(name="状态机")
public class StateMachineController {
    @Resource
    private OrderServiceImpl orderService;
    @Autowired
    private OrderMapper orderMapper;

/**
     * 根据id查询订单
     *
     * @return
     */

    @GetMapping("/getById")
    public Order getById(@RequestParam("id") Long id) {
        //根据id查询订单
        Order order = orderMapper.selectById(id);
        return order;
    }

/**
     * 创建订单
     *
     * @return
     */

    @PostMapping("/create")
    public String create(@RequestBody Order order) {
        //创建订单
        orderService.create(order);
        return "sucess";
    }
/**
     * 对订单进行支付
     *
     * @param id
     * @return
     */

    @GetMapping("/pay")
    public String pay(@RequestParam("id") Long id) {
        //对订单进行支付
        orderService.pay(id);
        return "success";
    }

/**
     * 对订单进行发货
     *
     * @param id
     * @return
     */

    @GetMapping("/deliver")
    public String deliver(@RequestParam("id") Long id) {
        //对订单进行确认收货
        orderService.deliver(id);
        return "success";
    }
/**
     * 对订单进行确认收货
     *
     * @param id
     * @return
     */

    @GetMapping("/receive")
    public String receive(@RequestParam("id") Long id) {
        //对订单进行确认收货
        orderService.receive(id);
        return "success";
    }
}
